<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>客户体检信息健康管理系统</title>
    <meta name="description" content="客户体检信息健康管理系统">
    <meta name="keywords" content="客户体检信息健康管理系统">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../plugins/jquery.datetime.picker/jquery.datetimepicker.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>体检预约管理<small>体检预约</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>体检预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>体检预约</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="套餐编码/套餐名称" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <!--<el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>-->
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="套餐名称" align="center"></el-table-column>
                <el-table-column prop="age" label="适用年龄" align="center"></el-table-column>
                <el-table-column prop="price" label="价格" align="center"></el-table-column>
                <el-table-column prop="sex" label="性别" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="price" label="价格" align="center"></el-table-column>
                <el-table-column prop="remark" label="描述" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">
                            预约
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增检查项" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="项目编码" prop="code">
                                    <el-input v-model="formData.code"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="项目名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="不限" value="0"></el-option>
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="适用年龄">
                                    <el-input v-model="formData.age"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="类型">
                                    <el-select v-model="formData.type">
                                        <el-option label="检查" value="1"></el-option>
                                        <el-option label="检验" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="价格">
                                    <el-input v-model="formData.price"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="项目说明">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="注意事项">
                                    <el-input v-model="formData.attention" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="体检预约"
                           :visible.sync="dialogFormVisibleEdit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form :rules="rules" ref="dataAddForm" :model="formData" label-position="right"
                                         label-width="100px">
                                    <el-row v-if="user.roles[0].keyword !='ROLE_PATIENT'">
                                        <el-col :span="12">
                                            <el-form-item label="体检人">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="健康管理师" prop="userId">
                                                <el-select v-model="formData.userId" placeholder="请选择">
                                                    <el-option
                                                            v-for="(item,index) in userList"
                                                            :key="item.id"
                                                            :label="item.username"
                                                            :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <!-- <el-col :span="12">
                                             <el-form-item label="身份证号" prop="idCard">
                                                 <el-input v-model="formData.idCard"/>
                                             </el-form-item>
                                         </el-col>-->
                                        <!--<el-col :span="12">
                                            <el-form-item label="">
                                                <el-input v-model="formData.orderDate" type="text" class="picktime"
                                                       readonly></el-input>
                                            </el-form-item>
                                        </el-col>-->
                                        <!-- <div class="date">
                                             <label>体检日期</label>
                                             <i class="icon-date" class="picktime"></i>
                                             <input v-model="orderInfo.orderDate" type="text" class="picktime" readonly>
                                         </div>-->
                                        <!--v-if="user.roles[0].keyword !='ROLE_PATIENT'"-->
                                        <el-col :span="12" v-if="user.roles[0].keyword !='ROLE_PATIENT'">
                                            <el-form-item label="性别" prop="sex">
                                                <!--<el-input v-model="formData.sex==0?'不限':formData.sex=='1'?'男':'女'"/>-->
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="描述" prop="remark">
                                                <el-input v-model="formData.remark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="预约日期列表" name="second">
                                <el-table
                                        ref="multipleTable"
                                        :data="tableData"
                                        height="250"
                                        tooltip-effect="dark"
                                        style="width: 100%"
                                        @selection-change="handleSelectionChange">
                                    <el-table-column
                                            align="center"
                                            type="selection"
                                            width="55">
                                    </el-table-column>
                                    <el-table-column
                                            fixed
                                            align="center"
                                            prop="orderDate_Copy"
                                            label="可预约的日期"
                                            width="180">
                                    </el-table-column>
                                    <el-table-column
                                            fixed
                                            prop="number"
                                            label="可预约人数"
                                            width="180"
                                            align="center">
                                    </el-table-column>
                                    <el-table-column
                                            fixed
                                            prop="reservations"
                                            label="已预约人数"
                                            align="center">
                                    </el-table-column>
                                </el-table>
                                <!--<div class="checkScrol">

                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>可预约的日期</th>
                                            <th>可预约人数</th>
                                            <th>已预约人数</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="orderIds" type="checkbox"
                                                       :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.orderDate}}</label></td>
                                            <td><label :for="c.id">{{c.number}}</label></td>
                                            <td><label :for="c.id">{{c.reservations}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>-->
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisibleEdit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit('dataAddForm')">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!--亚健康问卷-->
            <div class="add-form">
                <el-dialog title="亚健康评估问卷" :visible.sync="dialogFormAssessVisible" :before-close="handleClose">
                    <el-form ref="ruleForm" :inline="true" label-width="500px" class="demo-ruleForm">
                        <el-form-item v-for="(item,index) in arr" :key="index" :label="(index+1)+' '+item.title">
                            <el-checkbox-group v-model="item.type" :max="1">
                                <el-checkbox label="没有"></el-checkbox>
                                <el-checkbox label="有时有" @change="changeScore5"></el-checkbox>
                                <el-checkbox label="一直都是" @change="changeScore10"></el-checkbox>
                            </el-checkbox-group>
                        </el-form-item>
                        <el-form-item style="width: 100%;text-align:center;">
                            <el-button type="primary" @click="submitForm()">提交</el-button>
                            <el-button @click="resetAssessForm()">重置</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<!--<script type="text/javascript" src="../js/jquery.min.js"></script>-->
<script src="../plugins/jquery.datetime.picker/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../js/healthmobile.js"></script>
<script src="../plugins/jquery.datetime.picker/jquery.datetimepicker.full.min.js"></script>

<script>
    const vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {
                setmealId: '',
                orderDate: '',
                telephone: "",
                userId: ""
            },//表单数据
            reservations: '',
            number: '',
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisibleEdit: false,//编辑表单是否可见
            dialogFormAssessVisible: false,//评估问卷表单是否可见,
            userList: [],//查询健康管理师列表
            //评估问卷
            arr: [
                {
                    title: '是不是早上不想起床，即使起床也觉得浑身疲倦，整天打哈欠？',
                    type: []
                },
                {
                    title: '有没有觉得食欲差，什么也不想吃，但见到辛辣刺激或油炸食品就来劲？',
                    type: []
                }, {
                    title: '有没有觉得肩颈部容易酸痛，或者手脚发胀、发麻、发凉，又或者经常腹胀、腹泻、便秘？',
                    type: []
                },
                {
                    title: '有没有觉得别人都不好，都不理解你，脾气变得很坏，容易烦躁不安，事后又有所察觉，似乎自己太多事，钻了牛角尖？',
                    type: []
                },
                {
                    title: '天气变化，各种“流”侵袭，你是否首当其冲？',
                    type: []
                }, {
                    title: '总是想用茶或者咖啡来提神。',
                    type: []
                }
                , {
                    title: '有没有不明原因的体重下降，或者精力不济、体力不支，又或者身体有无名疼痛又检查不出病？',
                    type: []
                }
                , {
                    title: '是不是经常不吃早餐或者吃饭时间不固定？',
                    type: []
                }
                , {
                    title: '即使剧烈运动后也很少出汗。',
                    type: []
                },
                {
                    title: '注意力难以集中或健忘，越是眼前的事越容易忘掉。',
                    type: []
                },
                /*{
                    title: '是否经常情绪不舒感到有些抑郁，喜欢一个人发呆，不喜欢融入群体。',
                    type: []
                },
                {
                    title: '厌倦运动甚至懒得爬楼，或者爬楼时出现绊脚、膝盖酸软、腿脚无力的现象。',
                    type: []
                }
                , {
                    title: '会不会有心悸、胸闷、厌烦的感觉？',
                    type: []
                }
                , {
                    title: '回到家总是懒动，喜欢躺在沙发上，并把腿抬高才能感到舒服些。',
                    type: []
                }
                , {
                    title: '总是失眠，不易入睡或者容易惊醒，或者总是处于梦中，睡眠质量很差。并有脱发现象。',
                    type: []
                }*/
            ],
            score: 100,
            user: '',
            rules: {//校验规则
                userId: [{required: true, message: '健康管理师为必选项', trigger: 'change'}],
                sex: [{required: true, message: '性别为必选项', trigger: 'change'}],
                // idCard: [{required: true, message: '身份证号为必填项', trigger: 'blur'}],
                name: [{required: true, message: '体检人为必填项', trigger: 'blur'}]
            },
            option: false
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            //获取用户
            this.user = JSON.parse(localStorage.getItem("userInfo"));
            if (this.user.roles[0].keyword == "ROLE_PATIENT") {
                if (this.user.flag == 0) {
                    //打开亚健康问卷
                    this.dialogFormAssessVisible = true;
                    return false;
                } else {
                    this.findPage();
                }
            } else {
                this.findPage();
            }
        },
        methods: {
            changeScore5() {
                this.score = this.score - 5
            },
            changeScore10() {
                this.score = this.score - 10
            },
            submitForm() {
                let arr = this.arr;
                //判断数组是否选中
                for (let i = 0; i < arr.length; i++) {
                    if (arr[i].type.length === 0) {
                        this.$message({
                            message: "请至少选择一个",
                            type: "error"
                        })
                        return;
                    }
                }
                //判断分数
                if (this.score > 90) {
                    this.$confirm(`你的得分是${this.score}分! 您的身体倍儿棒，继续保持良好的生活习惯，保持积极乐观心态、疾病会离你远远滴`, '结果', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                } else if (this.score >= 70 && this.score < 90) {
                    this.$confirm(`你的得分是${this.score}分! 您的身体倍儿棒，继续保持良好的生活习惯，保持积极乐观心态、疾病会离你远远滴`, '结果', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                } else if (this.score >= 50 && this.score < 70) {
                    this.$confirm(`你的得分是${this.score}分! 黄色预警信号启动，您已处于中度亚健康状态，生命运动急需加强，生活饮食习惯急需改正`, '结果', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                } else if (this.score >= 25 && this.score < 50) {
                    this.$confirm(`你的得分是${this.score}分! 您的身体已经亮红灯了！请以健康的名义狠狠地爱自己！`, '结果', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                } else if (this.score >= 0 && this.score < 25) {
                    this.$confirm(`你的得分是${this.score}分! 不带这么折磨自己的！强烈建议，赶紧就医检查。`, '结果', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                }
                //重置表单
                this.resetAssessForm();
                //写入结果
                localStorage.setItem("flag", "true");
                //关闭弹窗
                this.dialogFormAssessVisible = false;
                //重新刷新
                this.findPage();
            },
            resetAssessForm() {
                for (let i = 0; i < this.arr.length; i++) {
                    this.arr[i].type = []
                }
            },
            //编辑
            handleEdit(forName) {
                //表单校验
                this.$refs[forName].validate((valid) => {
                    if (!valid) {
                        return false;
                    }
                    //校验身份证号格式
                    /*if (!checkIdCard(this.formData.idCard)) {
                        this.$message.error('身份证号码输入错误，请重新输入');
                        return;
                    }*/
                    if (this.formData.orderDate == null || this.formData.orderDate == '' || this.formData.orderDate == undefined) {
                        this.$message.warning("请先选定预约日期");
                        return;
                    }
                    //判断可预约人数与已预约人数
                    if (this.reservations >= this.number) {
                        this.$message.warning("预约人数已满，请重新选择");
                        return;
                    }
                    /*if (this.orderIds.length > 1) {
                        this.$message.warning("只可预约一次");
                        return;
                    }*/
                    this.option = this.$message({
                        type: "success",
                        message: "预约时间较久!,请稍微等待一两分钟"
                    })

                    //发送请求
                    axios.post("/order/add.do", this.formData).then((result) => {
                        //判断是否执行成功
                        if (result.data.flag) {
                            this.option.close();
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type: 'success',
                                message: result.data.message
                            });
                        } else {
                            //执行失败
                            this.$message.error(result.data.message);
                        }
                    }).catch((e) => {
                        // console.log(e)
                    }).finally((done) => {
                        this.dialogFormVisibleEdit = false
                        //重新进行分页查询
                        this.findPage();
                    })
                })
            },
            //添加
            handleAdd() {
            },
            //分页查询
            async findPage() {
                //查询套餐列表
                let result = await axios.post("/order/findPage.do", this.pagination);
                this.dataList = result.data.rows
                // console.log(this.dataList)
                this.pagination.total = result.data.total
            },
            // 重置表单
            resetForm() {
                if (this.$refs['dataAddForm'] !== undefined) {
                    this.$refs['dataAddForm'].resetFields();
                }
                this.formData = {}
            },
            // 弹出添加窗口
            handleCreate() {
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.resetForm()
                if (this.user.roles[0].keyword == "ROLE_PATIENT") {
                    //获取数据
                    this.formData.telephone = this.user.telephone
                    this.formData.name = this.user.username
                    this.formData.sex = this.user.gender
                }
                this.formData.setmealId = row.id
                this.dialogFormVisibleEdit = true
                //默认切换到第一个标签页（基本信息）
                this.activeName = 'first';
                //发送ajax请求查询所有的角色信息，用于检查项表格展示
                axios.get("/orderSetting/findOrderSettings.do").then((res) => {
                    if (res.data.flag) {
                        //为模型数据赋值，通过VUE数据双向绑定进行信息的回显
                        this.tableData = res.data.data;
                        // console.log(this.tableData)
                        for (let i = 0; i < this.tableData.length; i++) {
                            this.tableData[i].orderDate_Copy = this.formatDate(this.tableData[i].orderDate)
                        }
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
                //查询健康管理师
                axios.get('/user/findUserRoleAll.do').then((result) => {
                    this.userList = result.data.data
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage
                this.findPage()

            },
            //关闭亚健康评估表单回调
            handleClose(done) {
                let flag = true;
                let arr = this.arr;
                //判断是否答完问卷
                for (let i = 0; i < arr.length; i++) {
                    if (arr[i].type.length <= 0) {
                        flag = false;
                    }
                }
                // console.log(flag)
                if (flag) {
                    done();
                }
            },
            //日期转字符串格式
            formatDate(dateStr) {
                if (dateStr != null) {
                    let newdateStr = dateStr.replace(/\d+(?=-[^-]+$)/, (a) => (parseInt(a, 10) - 1));  //字符串处理(月份)
                    let nums = newdateStr.match(/\d+/g);  //取数
                    let date = eval('new Date(' + nums + ')');  //转换
                    //重组
                    let datetime =
                        date.getFullYear() + "年" +  //年
                        ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + "月" +  //月
                        (date.getDate() > 9 ? date.getDate() : ("0" + date.getDate())) + "日";  //日
                    return datetime;
                }

            },
            // 删除
            handleDelete(row) {
            },
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                if (val.length > 1) {
                    this.$message.warning("只可预约一次");
                    return;
                }
                if (val[0]) {
                    this.formData.orderDate = val[0].orderDate;
                    //获取可预约人数和已预约人数
                    this.reservations = val[0].reservations;
                    this.number = val[0].number;
                }

            }
        }
    })
    /*//日期控件
    const calendar = new datePicker();
    calendar.init({
        'trigger': '.picktime',/!*按钮选择器，用于触发弹出插件*!/
        'type': 'date',/!*模式：date日期；datetime日期时间；time时间；ym年月；*!/
        'minDate': getSpecifiedDate(new Date(), 1),/!*最小日期*!/
        'maxDate': getSpecifiedDate(new Date(), 30),/!*最大日期*!/
        'onSubmit': function () { /!*确认时触发事件*!/
        },
        'onClose': function () { /!*取消时触发事件*!/
        }
    });*/
</script>
</html>